package cn.wolfcode.crm.serivce.impl;

import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.query.ProductQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.serivce.IProductService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service
public class ProductServiceImpl implements IProductService{
    @Autowired
    private ProductMapper mapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Product record) {
        if (record.getId() == null) {
            //保存操作

            mapper.insert(record);
        }else {
            mapper.updateByPrimaryKey(record);
        }
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public PageResult query(ProductQueryObject qo) {

        Integer total = mapper.count(qo);
        if (total > 0) {
            List<Product> rows = mapper.query(qo);

            return new PageResult(total,rows);
        }
        return new PageResult(0, Collections.EMPTY_LIST);
    }

    @Override
    public List<Product> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public Long count() {
        return mapper.countId();
    }

    @Override
    public Map<String,Object> money() {
        return mapper.money();
    }
}
